﻿
namespace Mulala.Cavan.TestAppService.ConsignModule
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using NUnit.Framework;
    using Spring.Context;
    using Spring.Context.Support;
    using Mulala.Cavan.Application.MainBoundedContext.ConsignModule;
    using Mulala.Cavan.Domain.MainBoundedContext.ConsignModule;
    using Mulala.Cavan.Application.MainBoundedContext.ProprietorModule;
    using Mulala.Cavan.Application.MainBoundedContext.MulalaModule;
    using Mulala.Cavan.Domain.MainBoundedContext.ProprietorModule;
    using Mulala.Cavan.Domain.MainBoundedContext.DictionaryModule;
    using Mulala.Cavan.Domain.MainBoundedContext.Setting;
    using Mulala.Cavan.Domain.MainBoundedContext.NannyModule;
    using Mulala.Cavan.Domain.Seedwork;
    using Mulala.Cavan.Application.MainBoundedContext.SecurityModule;

    [TestFixture]
    public class TestConsignAppService
    {
        private IApplicationContext context;
        private IConsignAppService consignAppService;
        private IProprietorAppService proprietorAppService;
        private IUserAccountAppService userAccountAppService;
        private IAreaAppService areaAppService;

        [SetUp]
        public void SetUp()
        {
            context = ContextRegistry.GetContext();
        }

        [Test]
        public void TestAddConsign()
        {
            areaAppService = context.GetObject(MulalaAppServiceConst.AREAAPPSERVICE) as IAreaAppService;
            Area area = areaAppService.GetById("0201");
            proprietorAppService = context.GetObject(MulalaAppServiceConst.PROPRIETORAPPSERVICE) as IProprietorAppService;
            consignAppService = context.GetObject(MulalaAppServiceConst.CONSIGNAPPSERVICE) as IConsignAppService;
            userAccountAppService = context.GetObject(MulalaAppServiceConst.USERACCOUNTAPPSERVICE) as IUserAccountAppService;
            Proprietor proprietor = proprietorAppService.GetById(24);
            proprietor.UserAccount = userAccountAppService.GetById(24);
            Consign newConsign = ConsignFactory.CreateConsign(proprietor, "测试委托", -1, -1, area, "测试地址", -1, 2, 0, 0, 0, ConsignIdentifier.MarriedNeed.Both,
                ConsignIdentifier.HasChildrenNeed.Both, -1, -1, 0, DateTime.Now.AddMonths(3), ConsignIdentifier.ConsignType.FindBoth, ConsignIdentifier.ConsignRange.All,
                ConsignIdentifier.ConsignStatus.IsBidding, "测试", "18933912345","", ConsignIdentifier.CheckedStatus.UnChecked, 
                DateTime.Parse(Project.Settings.DefaultTime), DateTime.Parse(Project.Settings.DefaultTime), null, DateTime.Now, proprietor.UserAccount.Name);

           BoolGenericResult<Consign> result = consignAppService.Add(newConsign);
           Assert.Greater(result.Object.ID, 0);
        }

        [Test]
        public void TestAddConsignBidder()
        {
            Consign consign = ConsignFactory.CreateConsign(1);
            Nanny nanny = NannyFactory.CreateNanny(33);
            consignAppService = context.GetObject(MulalaAppServiceConst.CONSIGNAPPSERVICE) as IConsignAppService;
            BoolGenericResult<ConsignBidder> result = consignAppService.AddConsignBidder(consign, nanny);

            Assert.Greater(result.Object.ID, 0);
        }
    }
}
